package com.huanyang.exception;

import com.huanyang.protocol.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理类
 */
@RestControllerAdvice
public class GlobalExceptionHandle {

    private static Logger logger = LoggerFactory.getLogger(GlobalExceptionHandle.class);

    @ExceptionHandler({RuntimeException.class})
    public Result runtimeException(RuntimeException exception) {
        logger.error("global exception ", exception);
        return Result.fail();
    }

    @ExceptionHandler({Exception.class})
    public Result exception(Exception exception) {
        logger.error("global exception ", exception);
        return Result.fail();
    }
}
